package com.pxst.sys.mapper;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pxst.sys.entity.AuthorityEntity;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/** 
* @author yangxy
* @version 创建时间：2023年7月27日 下午4:03:01 
*/
@Repository
public interface AuthorityMapper extends BaseMapper<AuthorityEntity> {
	/**
	 * 根据用户ID获取用户拥有的权限
	* @author yangxy
	* @version 创建时间：2023年7月27日 下午4:39:40 
	* @param userId
	* @return
	 */
	@Select(value = "SELECT "
			+ "	distinct auth.*  "
			+ "FROM "
			+ "	sys_admin_authority auth "
			+ "	LEFT JOIN sys_admin_role_authority roleAuth ON auth.id = roleAuth.authority_id "
			+ "WHERE "
			+ "	EXISTS ( "
			+ "	SELECT "
			+ "		1  "
			+ "	FROM "
			+ "		sys_admin_user_roles userRole  "
			+ "	WHERE "
			+ "		userRole.role_id = roleAuth.role_id  "
			+ "		AND EXISTS ( SELECT 1 FROM sys_admin_role role WHERE role.id = userRole.role_id AND role.is_use = 1 )  "
			+ "		and userRole.user_id = #{userId} "
			+ "	)  "
			+ "	AND auth.is_use = 1")
	List<AuthorityEntity> getHaveAuthByUserId(@Param("userId") Long userId);



	/**
	 * @Author: @Ryan
	 * @Description: 根据id列表，批量将is_use修改为指定状态
	 * @Date: 2023/9/6 10:39
	 * @Param: [idList, is_use]
	 * @return: java.lang.Integer
	 **/
	Integer changeIsUse(@Param("idList") List<Long> idList, @Param("is_use") Integer is_use);
}
